package com.stanley.alogrithm.string;

import java.util.ArrayList;

public class LastWordLength {

    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        ArrayList<Integer> list2 = new ArrayList<>(list);
    }
    public int lengthOfLastWord(String s) {
        if (s == null || s.isEmpty()) {
            return 0;
        }
        int maxLen = 0;
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (c != ' ') {
                if (i > 0 && s.charAt(i - 1) == ' ') {
                    maxLen = 1;
                } else {
                    maxLen++;
                }
            }
        }
        return maxLen;
    }
}
